<?php

namespace addons\qingdongams\controller;

use addons\qingdongams\model\Message;
use  addons\qingdongams\model\WorkReport as WorkreportModel;
/**
 * 工作报告
 */
class Workreport extends StaffApi
{
    protected $noNeedLogin = [];
    protected $noNeedRight = [];

    //获取工作报告
    public function getList()
    {
        $staff_id = input('staff_id');
        $type = input('type');//日 周 月 季 年
        $times = input('times');//时间

        $where = [];
        if ($staff_id) {
            $where['staff_id'] = $staff_id;
        }
        if ($type) {
            $where['type'] = $type;
        }
        if ($times) {
            $times=setTimes($times,'date');
            $where['report_date'] = ['between', $times];
        }
        $list = WorkreportModel::where($where)->with(['staff'])->order('id desc')->paginate();

        $this->success('请求成功', $list);
    }

    //获取报告详情
    public function getDetail()
    {
        $id = input('id');

        $detail = WorkreportModel::where(['id' => $id])->with(['staff'])->find();
        if (empty($detail)) {
            $this->error('报告不存在');
        }
        //标记通知已读
        Message::setRead(Message::WORKREPORT_TYPE, $id, $this->auth->id);

        $this->success('请求成功', $detail);
    }

}
